package com.appbee.article.client.ui;

import javax.inject.Singleton;

import com.appbee.article.client.presenter.ArticleSettings;
import com.appbee.core.client.modular.SettingsView;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

@Singleton
public class ArticleSettingsView extends Composite implements SettingsView
{

	private static ArticleSettingsViewUiBinder uiBinder = GWT
			.create(ArticleSettingsViewUiBinder.class);

	interface ArticleSettingsViewUiBinder extends
			UiBinder<Widget, ArticleSettingsView>
	{
	}

	@UiField
	TextBox articleId;
	
	public ArticleSettingsView()
	{
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setSettingsString(String value)
	{
		ArticleSettings settings = new ArticleSettings(value);

		articleId.setValue(settings.getArticleId());
	}

	@Override
	public String toSettingsString()
	{
		ArticleSettings settings = new ArticleSettings();
		settings.setArticleId(articleId.getValue());
		String settingsString = settings.toSettingsString();
		GWT.log("Settings: " + settingsString);
		return settingsString;
	}
}
